1 using UnityEngine;
2 using
System.Collections;
3
4
5 public
class PositionTweenProperty : AbstractVector3TweenProperty
6 {
7     
protected bool _useLocalPosition;
8     
public bool useLocalPosition { get { return _useLocalPosition; } }
9     
10     
public PositionTweenProperty( Vector3 endValue, bool isRelative = false, bool useLocalPosition = false ) : base( endValue, isRelative )
11     {
12         _useLocalPosition = useLocalPosition;
13     }
14     
15     
16     
#region Object overrides
17     
18     
public override int GetHashCode()
19     {
20         
return base.GetHashCode();
21     }
22     
23     
24     
public override bool Equals( object obj )
25     {
26         
// start with a base check and then compare if we are both using local values
27         
if( base.Equals( obj ) )
28             
return this._useLocalPosition == ((PositionTweenProperty)obj)._useLocalPosition;
29         
30         
// if we get here, we need to see if the other object is a position path tween of the same kind
31         
var otherAsPositionPath = obj as PositionPathTweenProperty;
32         
if( otherAsPositionPath != null )
33             
return this._useLocalPosition == otherAsPositionPath.useLocalPosition;
34         
35         
return false;
36     }
37     
38     
#endregion
39
40     
41     
public override void prepareForUse()
42     {
43         _target = _ownerTween.target
as Transform;
44         
45         _endValue = _originalEndValue;
46         
47         
// if this is a from tween we need to swap the start and end values
48         
if( _ownerTween.isFrom )
49         {
50             
if( _useLocalPosition )
51             {
52                 
if (_isRelative)
53                     _startValue = _target.localPosition + _endValue;
54                 
else
55                     _startValue = _endValue;
56
57                 _endValue = _target.localPosition;
58             }
59             
else
60             {
61                 
if (_isRelative)
62                     _startValue = _target.position + _endValue;
63                 
else
64                     _startValue = _endValue;
65
66                 _endValue = _target.position;
67             }
68         }
69         
else
70         {
71             
if( _useLocalPosition )
72                 _startValue = _target.localPosition;
73             
else
74                 _startValue = _target.position;
75         }
76         
77         
base.prepareForUse();
78     }
79     
80
81     
public override void tick( float totalElapsedTime )
82     {
83         
var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
84         
var vec = GoTweenUtils.unclampedVector3Lerp( _startValue, _diffValue, easedTime );
85         
86         
if( _useLocalPosition )
87             _target.localPosition = vec;
88         
else
89             _target.position = vec;
90     }
91
92 }



Trò chơi Angry Birds trong UNITY Engine 31.651 lượt xem

Gõ tìm kiếm nhanh...